package com.leyou.order.listener;

import com.leyou.order.service.OrderService;
import com.leyou.seckill.dto.OrderSecKillDTO;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.leyou.common.constants.RocketMQConstants.CONSUMER.ORDER_OVERTIME_CONSUMER;
import static com.leyou.common.constants.RocketMQConstants.CONSUMER.SECKILL_ORDER_CONSUMER;
import static com.leyou.common.constants.RocketMQConstants.TAGS.ORDER_OVERTIME_TAGS;
import static com.leyou.common.constants.RocketMQConstants.TAGS.SECKILL_ORDER_TAGS;
import static com.leyou.common.constants.RocketMQConstants.TOPIC.ORDER_TOPIC_NAME;

@RocketMQMessageListener(consumerGroup =SECKILL_ORDER_CONSUMER,topic = ORDER_TOPIC_NAME,selectorExpression = SECKILL_ORDER_TAGS)
@Component
public class CreateSeckillOrderListener implements RocketMQListener<OrderSecKillDTO> {

    @Autowired
    private OrderService orderService;


    public void onMessage(OrderSecKillDTO orderSecKillDTO) {
        orderService.saveSeckillOrder(orderSecKillDTO);
    }
}
